<script setup>
import {reactive} from "vue";
// 引入Element Plus图标
import {
  Operation,
  User,
  Notebook,
  House,
  Key,
  ZoomOut,
  Menu as MenuIcon, Pointer, GoldMedal, Medal, Discount, TrophyBase, Film, Memo, Avatar, Calendar
} from '@element-plus/icons-vue'
import {removeJwt} from "@/api/jwt.js";
import router from "@/router/index.js";

// 导航栏数据（添加图标映射）
const menuItems = reactive([
  {
    name: "数据看板",
    url: "/main/charts",
    icon: Operation
  },
  {
    name: "会员管理",
    children: [
      {
        name: "会员列表",
        url: "/main/member",
        icon: Avatar
      }, {
        name: "预约列表",
        url: "/main/reservation",
        icon: Discount
      }
    ],
    icon: User
  },
  {
    name: "课程管理",
    children: [
      {
        name: "课程列表",
        url: "/main/course",
        icon: Film
      },
      {
        name: "教室列表",
        url: "/main/classroom",
        icon: House
      }, {
        name: "预约管理",
        url: "/main/reservationControl",
        icon: Memo
      }, {
        name: "课程日历",
        url: "/main/calendar",
        icon: Calendar
      }
    ],
    icon: Notebook
  },
  {
    name: "教练管理",
    children: [
      {
        name: "教练列表",
        url: "/main/coach",
        icon: TrophyBase
      }
    ],
    icon: GoldMedal
  },
  {
    name: "权限管理",
    children: [
      {
        name: "管理员管理",
        url: "/main/admin",
        icon: Pointer
      }
    ],
    icon: Key
  }
])

// 注销功能
function close() {
  removeJwt();
  router.push('/login')
}
</script>

<template>
  <div class="common-layout h100">
    <el-container class="h100">
      <!-- 头部区域 -->
      <el-header class="header-container">
        <div class="logo-container">
          <div class="logo-icon">
            <el-icon>
              <MenuIcon/>
            </el-icon>
          </div>
          <div class="logo-text">YOGA会馆管理系统</div>
        </div>
        <div class="user-actions">
          <el-button
              type="text"
              icon="ZoomOut"
              @click="close"
              class="logout-btn"
          >
            注销
          </el-button>
        </div>
      </el-header>

      <el-container>
        <!-- 侧边栏导航 -->
        <el-aside width="200px" class="aside-container">
          <el-menu
              class="nav-menu"
              text-color="#e0e0e0"
              active-text-color="#409eff"
              background-color="#2c3e50"
              default-active="/charts"
              router
              :collapse-transition="true"
          >
            <template v-for="(mi, index) in menuItems" :key="index">
              <el-sub-menu
                  v-if="Array.isArray(mi.children)"
                  :index="mi.name"
                  popper-class="submenu-popup"
              >
                <template #title>
                  <el-icon :size="18" class="menu-icon">
                    <component :is="mi.icon"/>
                  </el-icon>
                  <span>{{ mi.name }}</span>
                </template>
                <el-menu-item
                    v-for="(child, cIndex) in mi.children"
                    :key="cIndex"
                    :index="child.url"
                    class="submenu-item"
                >
                  <el-icon :size="16" class="submenu-icon">
                    <component :is="child.icon"/>
                  </el-icon>
                  <span>{{ child.name }}</span>
                </el-menu-item>
              </el-sub-menu>

              <el-menu-item v-else :index="mi.url" class="menu-item">
                <el-icon :size="18" class="menu-icon">
                  <component :is="mi.icon"/>
                </el-icon>
                <span>{{ mi.name }}</span>
              </el-menu-item>
            </template>
          </el-menu>
        </el-aside>

        <!-- 主内容区域 -->
        <el-container>
          <el-main class="main-content">
            <router-view>

            </router-view>
          </el-main>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped>
.h100 {
  height: 100vh;
  margin: 0;
  padding: 0;
}

/* 头部样式 */
.header-container {
  background-color: #2c3e50;
  height: 60px !important;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  color: #409eff;
  font-size: 24px;
}

.logo-text {
  color: #ffffff;
  font-size: 18px;
  font-weight: 500;
}

.user-actions {
  display: flex;
  align-items: center;
}

.logout-btn {
  color: #e0e0e0;
  transition: all 0.3s;
}

.logout-btn:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.1);
}

/* 侧边栏样式 */
.aside-container {
  background-color: #2c3e50;
  border-right: 1px solid #34495e;
  transition: all 0.3s;
}

.nav-menu {
  border-right: none;
  height: 100%;
  padding-top: 15px;
}

.menu-item, .submenu-item {
  transition: all 0.2s;
  padding-left: 25px !important;
}

.menu-item:hover, .submenu-item:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

.menu-item.is-active, .submenu-item.is-active {
  background-color: #34495e !important;
}

.menu-icon, .submenu-icon {
  margin-right: 10px;
}

.submenu-popup {
  background-color: #34495e !important;
}

/* 主内容区域 */
.main-content {
  background-color: #f5f7fa;
  padding: 20px;
  overflow-y: auto;
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}
</style>